﻿/***************************************************************************
//* Foxit Software Inc.
//* Copyright(C) 2005-2012, all rights reserved.
//*
//* The following code is copyrighted and contains proprietary information
//* and trade secrets of Foxit Software Inc.                                                      *
***************************************************************************/
/**
* Link Annot 
*/
define(function (require, exports, module) {
    var CPDF_Annot = require('./Annot.js');
    var InterfaceImpl = require('../Interface');
    var CPDF_Action = require('./Action');
    var AnnotDataFmt = FXREADER.PDFData.AnnotDataJsonFormat;
    var CPDF_LinkAnnot = function (jsonData) {
        CPDF_LinkAnnot.superclass.constructor.call(this, jsonData); //调用父类构造函数
        this.Dest = null;
        this.Action = null;
    };
    InterfaceImpl.extend(CPDF_LinkAnnot, CPDF_Annot); //派生

    CPDF_LinkAnnot.prototype.SetHighLight = function (nHighlight) {
        this.m_AnnotData[AnnotDataFmt.highlight] = nHighlight;
    };

    CPDF_LinkAnnot.prototype.GetHighLight = function () {
        return this.m_AnnotData[AnnotDataFmt.highlight];
    };

    CPDF_LinkAnnot.prototype.SetQuadPoints = function (new_points) {
        if (new_points.length != 4) {
            throw new Error("SetQuadPoints:Only 4 points supported!");
        }
        var quad_points = [];
        for (var i = 0; i < 4; i++) {
            var fp = points[i];
            quad_points.push(fp.x);
            quad_points.push(fp.y);
            var rect = new FXREADER.PDFData.CPDF_Rect(0, 0, 0, 0);
            if (i == 0) {
                rect.left = rect.right = fp.x;
                rect.bottom = rect.top = fp.y;
            }
            else {
                if (rect.left > fp.x) rect.left = fp.x;
                if (rect.bottom > fp.y) rect.bottom = fp.y;
                if (rect.right < fp.x) rect.right = fp.x;
                if (rect.top < fp.y) rect.top = fp.y;
            }
        }
        this.SetRect(rect);
        this.m_AnnotData[AnnotDataFmt.QuadPoints] = quad_points;
    };

    CPDF_LinkAnnot.prototype.GetQuadPoints = function () {
        var quad_points = new Array();
        for (var i = 0, sz = this.m_AnnotData[AnnotDataFmt.QuadPoints].length; i < sz; i += 2) {
            var x = this.m_AnnotData[AnnotDataFmt.QuadPoints][i];
            var y = this.m_AnnotData[AnnotDataFmt.QuadPoints][i + 1];

            quad_points.push(new FXREADER.PDFData.CPDF_Point(x, y));
        }
        return quad_points;
    };

    CPDF_LinkAnnot.prototype.IsQuadLink = function () {
        return this.m_AnnotData[AnnotDataFmt.QuadPoints] != null && this.m_AnnotData[AnnotDataFmt.QuadPoints].length % 8 == 0;
    };

    CPDF_LinkAnnot.prototype.GetDestination = function () {
        if (this.Dest == null) {
            this.Dest = new FXREADER.PDFData.CPDF_DestInfo(this.m_AnnotData[AnnotDataFmt.DestInfo]);
        }
        return this.Dest;
    }

    CPDF_LinkAnnot.prototype.GetAction = function () {
        if (this.m_AnnotData.act == null)
            return null;
        if (this.Action == null) {
            this.Action = new CPDF_Action(this.m_AnnotData[AnnotDataFmt.Action]);
        }
        return this.Action;
    }

    FXREADER.PDFData.CPDF_LinkAnnot = CPDF_LinkAnnot;
    return FXREADER.PDFData.CPDF_LinkAnnot;


});